package manager.listerner;
import com.rabbitmq.client.Channel;
import manager.goods.service.GoodsService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
@Component
public class OrderListerner {
        @Autowired
        private GoodsService goodsService;
        @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "crmshop.stock.queen", durable = "true"),
            exchange = @Exchange(value = "crmshop.stock.exchange",ignoreDeclarationExceptions = "true"),
            key = {"stock.update.decrease"}))
            public void listenSms(List<Map<String,String>> message, Message msg, Channel channel) throws Exception {
                    if (msg == null || msg.getBody().length <= 0) {
                        return;
                    }
                    goodsService.updateStock(message);
            }
}
